/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controleur;

import ecouteurs.EcouteurStartParcours;
import ia_multiagent1.Agent;
import ia_multiagent1.Espace2D;
import ia_multiagent1.LogAgent;
import java.awt.BorderLayout;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import vue.JPanelGrid;

/**
 *
 * @author Christine
 */
public class RunParcours implements Runnable{
    
    private Vector<Agent> agents;
    private JTextField txt;
    private int dimGridCases;
    private int dimPixelCase;
    private Espace2D e2d;
    private boolean disparitionPheromones = false;
            
            
    public RunParcours(Vector<Agent> agents, JTextField txt, int dimGridCases, int dimPixelCase, Espace2D e2d){
        this.agents = agents;
        this.txt = txt;
        this.dimGridCases = dimGridCases;
        this.dimPixelCase = dimPixelCase;
        this.e2d = e2d;
    }

    public void run() {
        Controleur.writeHistoireFormatee((Integer.parseInt(txt.getText())-1), "parcours_agent_"+System.currentTimeMillis()+".log");
        
        JFrame jf = new JFrame();
        jf.setSize(1000, 1000);
        Vector<LogAgent> logAgent = agents.elementAt(Integer.parseInt(txt.getText())-1).getHistorique();
        Agent myAgent = new Agent(logAgent.elementAt(0).getX(), logAgent.elementAt(0).getY(), dimGridCases, e2d, 0, disparitionPheromones, false);
 
        JPanelGrid content = new JPanelGrid(dimGridCases,dimPixelCase, myAgent, e2d,false,false);
        
        
        jf.setLayout(new BorderLayout()); 
        jf.getContentPane().add(content, BorderLayout.CENTER);
        
        
        JLabel lblWait = new JLabel("Temps entre chaque déplacement (en millisecondes)");
        JTextField txtWait = new JTextField("200");
        
        JButton start = new JButton("    Start    ");
        start.addMouseListener(new EcouteurStartParcours(myAgent, logAgent, content, txtWait));
        JPanel panStart = new JPanel();
        panStart.add(lblWait);
        panStart.add(txtWait);
        panStart.add(start);
        jf.getContentPane().add(panStart, BorderLayout.SOUTH);
        
        jf.setTitle("Parcours effectué par l'agent");
        jf.setVisible(true);
    }

}
